package com.sxc.servletContext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/sc02")
public class servletContext02 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = req.getServletContext();
        // 设置域对象
        servletContext.setAttribute("name", "zhangsan");
        // 获取域对象
        String name = (String) servletContext.getAttribute("name");
        // 移除域对象
        System.out.println("name = " + name);
        servletContext.removeAttribute("name");
    }
}
